package labelsystem.utils;/**
 * @projectName careOlder
 * @Description TODO
 * @author MCG
 * @time 2023/3/23 11:04
 */

import labelsystem.Pojo.Monitor;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 *description: 处理monitor将其转换为需要的类型
 *@author MCG
 *@date 2023/3/23 11:04
 *@Version 1.0
 */
public class monitorHandle {
    Monitor monitor;
    //k-v对,k表示日期，v表示是否打卡
    Map<String,Character> map=new HashMap<>();

    public monitorHandle() {
    }

    public monitorHandle(Monitor monitor) {
        this.monitor = monitor;
        String bitmaps=monitor.getIsUsed();
        Date date = Date.from(monitor.getCreateTime().atZone(ZoneId.systemDefault()).toInstant());
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(date);
        for(int i=0;i<bitmaps.length();i++){
            String key=calendar.get(Calendar.YEAR)+"-"+(calendar.get(Calendar.MONTH)+1)+"-"+calendar.get(Calendar.DAY_OF_MONTH);
            calendar.add(Calendar.DATE,1);
            map.put(key,bitmaps.charAt(i));
        }
    }

    public Monitor getMonitor() {
        return monitor;
    }

    public void setMonitor(Monitor monitor) {
        this.monitor = monitor;
    }

    public Map<String, Character> getMap() {
        return map;
    }

    public void setMap(Map<String, Character> map) {
        this.map = map;
    }

    @Override
    public String toString() {
        return "monitorHandle{" +
                "monitor=" + monitor +
                ", map=" + map +
                '}';
    }
}
